package com.cy.hui_jie_dan.comon.utils;

import org.springframework.stereotype.Component;

import java.security.SecureRandom;

/**
 * 验证码
 */
@Component
public class SecureCaptchaGenerator {
    private static final String CHARACTERS = "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz";
    private static final SecureRandom random = new SecureRandom();

    public static String generateCaptcha(int length) {
        StringBuilder captcha = new StringBuilder(length);

        for (int i = 0; i < length; i++) {
            int index = random.nextInt(CHARACTERS.length());
            captcha.append(CHARACTERS.charAt(index));
        }

        return captcha.toString();
    }
}
